/*
* jlb
*/
package com.jlb.user.ctrl;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.annotation.Resource;
import java.util.List;
import java.util.HashMap;

import com.jlb.core.entity.BeanRet;
import com.jlb.core.entity.Page;
import com.jlb.core.tools.redis.RedisUtils;
import com.jlb.user.entity.UserGroup;
import com.jlb.user.service.UserGroupSV;

/**
 * 团队关系 控制器
 *
 * @author jlb
 */
@RestController
@RequestMapping("/userGroup")
@Slf4j
@Api(value = "团队关系控制器", description = "团队关系控制器")
public class UserGroupCtrl {

    @Resource
    protected RedisUtils redisUtils;

    @Resource
    private UserGroupSV userGroupSV;

    /**
     * 查询UserGroup一个详情信息
     *
     * @param id
     * @param userCode    用户编码
     * @param preUserCode 上级编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserGroup一个详情信息", notes = "查询UserGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "query"),
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", dataType = "java.lang.String", paramType = "query")
    })
    @GetMapping(value = "/load")
    @ResponseBody
    public BeanRet load(java.lang.Long id, java.lang.String userCode, java.lang.String preUserCode) {
        if (id == null) {
            return null;
        }
        if (userCode == null) {
            return null;
        }
        if (preUserCode == null) {
            return null;
        }
        UserGroup userGroup = userGroupSV.load(id, userCode, preUserCode);
        log.info(JSON.toJSONString(userGroup));
        return BeanRet.create(true, "查询成功", userGroup);
    }


    /**
     * 根据条件id查询UserGroup一个详情信息
     *
     * @param id
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserGroup一个详情信息", notes = "查询UserGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", dataType = "java.lang.Long", paramType = "path")
    })
    @GetMapping(value = "/load/id/{id}")
    @ResponseBody
    public BeanRet loadById(@PathVariable java.lang.Long id) {
        if (id == null) {
            return null;
        }
        UserGroup userGroup = userGroupSV.loadById(id);
        log.info(JSON.toJSONString(userGroup));
        return BeanRet.create(true, "查询成功", userGroup);
    }

    /**
     * 根据条件userCode查询UserGroup一个详情信息
     *
     * @param userCode 用户编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserGroup一个详情信息", notes = "查询UserGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userCode", value = "用户编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/userCode/{userCode}")
    @ResponseBody
    public BeanRet loadByUserCode(@PathVariable java.lang.String userCode) {
        if (userCode == null) {
            return null;
        }
        UserGroup userGroup = userGroupSV.loadByUserCode(userCode);
        log.info(JSON.toJSONString(userGroup));
        return BeanRet.create(true, "查询成功", userGroup);
    }

    /**
     * 根据条件preUserCode查询UserGroup一个详情信息
     *
     * @param preUserCode 上级编码
     * @return BeanRet
     */
    @ApiOperation(value = "查询UserGroup一个详情信息", notes = "查询UserGroup一个详情信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", dataType = "java.lang.String", paramType = "path")
    })
    @GetMapping(value = "/load/preUserCode/{preUserCode}")
    @ResponseBody
    public BeanRet loadByPreUserCode(@PathVariable java.lang.String preUserCode) {
        if (preUserCode == null) {
            return null;
        }
        UserGroup userGroup = userGroupSV.loadByPreUserCode(preUserCode);
        log.info(JSON.toJSONString(userGroup));
        return BeanRet.create(true, "查询成功", userGroup);
    }


    /**
     * 查询UserGroup信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserGroup信息集合", notes = "查询UserGroup信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "createTimeBegin", value = "创建时间", paramType = "query"),
            @ApiImplicitParam(name = "createTimeEnd", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/list")
    @ResponseBody
    public BeanRet list(@ApiIgnore UserGroup userGroup, Integer curPage, Integer pageSize) {
        Page<UserGroup> page = new Page<UserGroup>(pageSize, curPage);
        List<UserGroup> userGroups = userGroupSV.list(userGroup, page.genRowStart(), page.getPageSize());
        page.setVoList(userGroups);
        int total = userGroupSV.count(userGroup);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);

    }


    /**
     * 查询UserGroup信息集合
     *
     * @return 分页对象
     */
    @ApiOperation(value = "查询UserGroup信息集合", notes = "查询UserGroup信息集合")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "curPage", value = "当前页", required = true, paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "分页大小", required = true, paramType = "query"),
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", paramType = "query")
    })
    @GetMapping(value = "/list/by")
    @ResponseBody
    public BeanRet listByPk(java.lang.Long id, java.lang.String userCode, java.lang.String preUserCode, Integer curPage, Integer pageSize) {
        Page<UserGroup> page = new Page<UserGroup>(pageSize, curPage);
        List<UserGroup> userGroups = userGroupSV.list(id, userCode, preUserCode, page.genRowStart(), page.getPageSize());
        page.setVoList(userGroups);
        int total = userGroupSV.count(id, userCode, preUserCode);
        page.setTotalRow(total);

        return BeanRet.create(true, "查询成功", page);
    }

    /**
     * 统计UserGroup信息数量根据主键
     *
     * @return 总条数
     */
    @ApiOperation(value = " 统计UserGroup信息数量根据主键", notes = " 统计UserGroup信息数量根据主键")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", paramType = "query")
    })
    @GetMapping(value = "/count/by")
    @ResponseBody
    public Integer count(java.lang.Long id, java.lang.String userCode, java.lang.String preUserCode) {
        return userGroupSV.count(id, userCode, preUserCode);
    }

    /**
     * 统计UserGroup信息数量
     *
     * @return 总条数
     */
    @ApiOperation(value = "统计UserGroup信息数量", notes = "统计UserGroup信息数量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @GetMapping(value = "/count")
    @ResponseBody
    public Integer count(@ApiIgnore UserGroup userGroup) {
        if (userGroup == null) {
            return userGroupSV.count(new HashMap());
        } else {
            return userGroupSV.count(userGroup);
        }
    }


    /**
     * 创建UserGroup
     *
     * @return BeanRet
     */
    @ApiOperation(value = "创建UserGroup", notes = "创建UserGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PostMapping("/build")
    @ResponseBody
    public BeanRet build(@ApiIgnore UserGroup userGroup) {
        userGroupSV.save(userGroup);
        return BeanRet.create(true, "创建成功", userGroup);
    }


    /**
     * 修改UserGroup
     *
     * @return BeanRet
     */
    @ApiOperation(value = "修改UserGroup", notes = "修改UserGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", paramType = "query"),
            @ApiImplicitParam(name = "createTime", value = "创建时间", paramType = "query")
    })
    @PutMapping("/modify")
    @ResponseBody
    public BeanRet modify(@ApiIgnore UserGroup userGroup) {
        userGroupSV.modify(userGroup);
        return BeanRet.create(true, "修改成功", userGroup);
    }

    /**
     * 删除UserGroup
     *
     * @return BeanRet
     */
    @ApiOperation(value = "删除UserGroup", notes = "删除UserGroup")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "", paramType = "query"),
            @ApiImplicitParam(name = "userCode", value = "用户编码", paramType = "query"),
            @ApiImplicitParam(name = "preUserCode", value = "上级编码", paramType = "query")
    })
    @DeleteMapping("/delete")
    @ResponseBody
    public BeanRet delete(java.lang.Long id, java.lang.String userCode, java.lang.String preUserCode) {
        userGroupSV.delete(id, userCode, preUserCode);
        return BeanRet.create(true, "删除UserGroup成功");
    }

}
